import os
import cv2


path1 = 'video-1.mp4'
path2 = 'video-2.mp4'

save_dir = 'video_images'
os.makedirs(save_dir, exist_ok=True)

i = 0
j = 0
ratio = 10

for path in [path1, path2]:
    cap = cv2.VideoCapture(path)
    # 检查视频是否成功打开
    if not cap.isOpened():
        print("Error: 无法打开视频文件.")

    # 循环读取视频帧
    while True:
        # 读取一帧
        ret, frame = cap.read()

        # 检查帧是否成功读取
        if not ret:
            print("Error: 无法读取视频帧.")
            break
        
        if j % ratio == 0:
            name = os.path.join(save_dir, f'{i:05d}.png')
            cv2.imwrite(name, frame)
            i += 1
            print(f'{name} has been saved!')
        j += 1
        
    cap.release()
    